package com.leehom.arch.base.i18n;

import java.util.Locale;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

/**
 * @类名: MessageSourceUtil
 * @说明: 消息资源工具类
 *
 * @author   leehom
 * @Date	 2019年10月30日 下午2:44:50
 * 修改记录：
 *
 * @see 	 
 */
public class MessageSourceUtil {

    /** messageSource*/
    private static MessageSource messageSource;

    // 
    public static String getMessage(String code, Locale locale) {
        return getMessage(code, null, locale);
    }

    public static String getMessage(String code, Object[] args, Locale locale) {
        return messageSource.getMessage(code, args, locale);
    }

    public static String getMessage(String code, Object[] args, String defaultMessage) {
        Locale locale = LocaleContextHolder.getLocale();
        return messageSource.getMessage(code, args, defaultMessage, locale);
    }

	public static MessageSource getMessageSource() {
		return messageSource;
	}

	public static void setMessageSource(MessageSource messageSource) {
		MessageSourceUtil.messageSource = messageSource;
	}

}
